﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNhaThuoc.BL;
using QLNhaThuoc.DTO;

namespace QLNhaThuoc.MyClass
{
    class PhieuHelper
    {
        public static void KiemTraNhanVienTonTai(object sender, CancelEventArgs e, NhanVienControl nhanVienCtrl, ErrorProvider errorProvider1, TextBox tbTenNV)
        {
            TextBox tmp = (TextBox)sender;
            string MaNV = tmp.Text;
            NhanVien nv = nhanVienCtrl.LayNhanVienTheoMa(MaNV);
            if (nv == null)
            {
                errorProvider1.SetError(tmp, "Mã nhân viên không tồn tại");
                e.Cancel = true;
            }
            else
            {
                errorProvider1.SetError(tmp, "");
                tbTenNV.Text = nv.Ho + " " + nv.Ten;
            }
        }

        public static void ValidateCell(DataGridView grv, DataGridViewCellEventArgs e, Thuoc thuoc)
        {
            grv.Rows[e.RowIndex].ErrorText = "";
            switch (grv.Columns[e.ColumnIndex].Name)
            {
                case "MaThuoc":
                    DataGridViewCell cellMaThuoc = grv.Rows[e.RowIndex].Cells["MaThuoc"];
                    cellMaThuoc.ErrorText = "";
                    cellMaThuoc.Value = cellMaThuoc.Tag;
                    break;
                case "SoLuong":
                    DataGridViewCell cellSoLuong = grv.Rows[e.RowIndex].Cells["SoLuong"];
                    cellSoLuong.ErrorText = "";
                    cellSoLuong.Value = cellSoLuong.Tag;
                    grv.Rows[e.RowIndex].Cells["ThanhTien"].Value = thuoc.DonGia * int.Parse(cellSoLuong.Value.ToString());
                    break;
            }
        }
    }
}
